#!/bin/sh

# the defined variables should be:
# CONSPIRE_WRITEABLEDIR
# CONSPIRE_KEYID
# CONSPIRE_TMAX
# CONSPIRE_CLUSTERID

export CONSPIRE_BROKERHOST=@DEFAULT_HOST@
export CONSPIRE_BROKERPORT=@DEFAULT_PORT@

export FINAL_QUEUEING_SCRIPT="cd $CONSPIRE_WRITEABLEDIR; \
if [ -n \"`which wget`\" ]; then \
   wget http://$CONSPIRE_BROKERHOST:$CONSPIRE_BROKERPORT/hosted_files/bootstrap.sh -O bootstrap_$CONSPIRE_KEYID.sh; \
else \
   curl http://$CONSPIRE_BROKERHOST:$CONSPIRE_BROKERPORT/hosted_files/bootstrap.sh > bootstrap_$CONSPIRE_KEYID.sh; \
fi; \
   chmod +x bootstrap_$CONSPIRE_KEYID.sh; \
   sh bootstrap_$CONSPIRE_KEYID.sh"

if [ "$CONSPIRE_CLUSTERID" = "pretend" ]; then
   export JOBNAME=`echo \("$FINAL_QUEUEING_SCRIPT"\) | qsub -V`
fi
if [ "$CONSPIRE_CLUSTERID" = "bluecrystalp1" ]; then
   module add torque
   export JOBNAME=`echo \("$FINAL_QUEUEING_SCRIPT"\) | qsub -V`
fi
if [ "$CONSPIRE_CLUSTERID" = "bluecrystalp2" ]; then
   module add torque
   if [ ! -f $HOME/lib/libapr-1.so.0 ] || [ ! -f $HOME/lib/libaprutil-1.so.0 ]; then
      mkdir -p $HOME/lib
      cp -L /usr/lib64/libapr-1.so.0 $HOME/lib/
      cp -L /usr/lib64/libaprutil-1.so.0 $HOME/lib/
   fi
   export JOBNAME=`echo \("$FINAL_QUEUEING_SCRIPT"\) | qsub -V`
fi
echo $JOBNAME
